<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
    <meta name="author" content="GeeksLabs">
    <meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
    <link rel="shortcut icon" href="img/favicon.png">
  </head>
  <body>
  <!-- 添加项目 -->
  <div class="modal-header">
                  <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                  <h4 class="modal-title">#if(type=="add")新增#else if(type=="reduce")减少#end余额</h4>
              </div>
              <div class="modal-body">
  <form role="form" id="inputForm">
    <input type="hidden" name="memberId" value="#(memberId)" id="memberId">
    <input type="hidden" name="type" value="#(type)" id="type">
    <input type="hidden" value="#(member.amount)" id="amount">
    				  <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">手机号码：</label>
                            <div class="col-sm-3">
                            	#(member.mobile)
                            </div>
                            </div>
                      </div>
                      <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">会员昵称：</label>
                            <div class="col-sm-3">
                            	#(member.nickname)
                            </div>
                            </div>
                      </div>
                      <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">会员头像：</label>
                            <div class="col-sm-3">
                            	<img src="#(member.avatar)" height="50"/>
                            </div>
                            </div>
                      </div>
                      <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">会员余额：</label>
                            <div class="col-sm-3">
                            	#(member.amount)
                            </div>
                            </div>
                      </div>
                      <div class="form-group">
                      <div class="row">
                            <label class="col-sm-3 control-label">金额：</label>
                            <div class="col-sm-3">
                            	<input class="form-control" type="text" name="money" id="money" value="">
                            </div>
                            </div>
                      </div>
                      <div class="row">
                      <label class="col-sm-3 control-label">&nbsp;</label>
                      <div class="col-sm-3">
                      <button type="button" class="btn btn-primary" style="margin-top: 20px;" id="saveRole">确定</button>
                      </div>
                      </div>
                  </form>
  
  </div>
  </body>
</html>

<script type="text/javascript">

$("#saveRole").on("click",function(){
	if(isEmpty($("#money").val())){
		alert("请输入金额!");
		return false;
	}  
	var money = $("#money").val();
	
	var moneyReg = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/;
	if (!moneyReg.test(money)){
	   alert("请输入正确的金额");
	  return false;
	}
	var type = $("#type").val();
	var amount = $("#amount").val();
	if(type=="reduce"){
		if(parseFloat(money)>parseFloat(amount)){
			alert("金额不能大于会员余额");
			return;
		}
	}
	$.ajax({
        url: "updateBalance",
        type: "POST",
        data: $("#inputForm").serialize(),
        dataType: "json",
        cache: false,
        success: function(response) {
        	if (response.type == "success") {
        		alert("操作成功");
        		location.reload();
            }else{
                swal({title:'', text:response.msg,icon: 'error'});
            }
        }
    });
	
});
</script>